package com.enqualcomm.kids.mvp.terminalbill;

import com.android.volley.VolleyError;
import com.enqualcomm.kids.mvp.NetworkModel;
import com.enqualcomm.kids.network.NetworkListener;
import com.enqualcomm.kids.network.SocketRequest;
import com.enqualcomm.kids.network.socket.request.GetCheckBillParams;
import com.enqualcomm.kids.network.socket.request.GetQuerySIMInfoWayParams;
import com.enqualcomm.kids.network.socket.request.SendCheckBillParams;
import com.enqualcomm.kids.network.socket.request.UpdateQuerySIMInfoWayParams;
import com.enqualcomm.kids.network.socket.response.AllBillResult;
import com.enqualcomm.kids.network.socket.response.BasicResult;
import com.enqualcomm.kids.network.socket.response.GetQuerySIMInfoWayResult;

/**
 * Created by Sunzhigang on 2015/11/2.
 */
public class CheckBillModel extends NetworkModel implements ICheckBillModel {

    @Override
    public void sendCheckbillCmd(String userkey,String userid,
                                 String terminalid,String username,final int traffic, final ICheckBillHandler handler) {

        SendCheckBillParams params = new SendCheckBillParams(userkey,userid,terminalid,username,traffic);
        loadDataFromServer(new SocketRequest<BasicResult>(params, new NetworkListener<BasicResult>() {
            @Override
            public void onError(VolleyError error) {

            }

            @Override
            public void onSuccess(BasicResult response) {
                handler.onSendSuccess(traffic);
            }
        }));
    }

    @Override
    public void getCheckBillResult(String userkey,String userid,String terminalid, final ICheckBillHandler handler) {
        GetCheckBillParams params = new GetCheckBillParams(userkey,userid,terminalid);
        loadDataFromServer(new SocketRequest<AllBillResult>(params, new NetworkListener<AllBillResult>() {
            @Override
            public void onError(VolleyError error) {

            }

            @Override
            public void onSuccess(AllBillResult response) {
                handler.onGetSuccess(response);
            }
        }));
    }

    @Override
    public void getCheckBillSettings(String userkey,String userid,String terminalid, final ICheckBillHandler handler) {
        GetQuerySIMInfoWayParams params = new GetQuerySIMInfoWayParams(userkey,userid,terminalid);
        loadDataFromServer(new SocketRequest<GetQuerySIMInfoWayResult>(params, new NetworkListener<GetQuerySIMInfoWayResult>() {
            @Override
            public void onError(VolleyError error) {

            }

            @Override
            public void onSuccess(GetQuerySIMInfoWayResult response) {
                handler.getCheckBillSettingsSuccess(response);
            }
        }));
    }

    @Override
    public void setCheckBillSettings(String userkey,String userid,String terminalid,
                                     String cxll,String cxye,String number, String numberll,final ICheckBillHandler handler) {
        UpdateQuerySIMInfoWayParams params = new UpdateQuerySIMInfoWayParams(userkey,userid,terminalid,cxll,cxye,number,numberll);
        loadDataFromServer(new SocketRequest<BasicResult>(params, new NetworkListener<BasicResult>() {
            @Override
            public void onError(VolleyError error) {

            }

            @Override
            public void onSuccess(BasicResult response) {
                if (response.code==0){
                    handler.setCheckBillSettingsSuccess();
                }

            }
        }));

    }
}
